/**
 * 主页js
 */

if (location.href =="http://tjj.jl.gov.cn/index.html" || location.href =="http://tjj.jl.gov.cn/") {
    //第一部分
    //二层

    //各个选项名称对应的内容数量
    _EsdDynamicTransformationScript.num1 = $("#con div:eq(0) a").length - 1;
    _EsdDynamicTransformationScript.num2 = $("#con div:eq(1) a").length - 1;

    //各个选项名称
    _EsdDynamicTransformationScript.esd1TagNum1 = $("#tit li:eq(0) a");
    _EsdDynamicTransformationScript.esd1TagNum2 = $("#tit li:eq(1) a");

    //各个选项中的第一个内容
    _EsdDynamicTransformationScript.esd1TagNum1Content1 = $("#con div:eq(0) a:eq(0)");
    _EsdDynamicTransformationScript.esd1TagNum2Content1 = $("#con div:eq(1) a:eq(0)");

    //各个选项中的最后一个内容
    _EsdDynamicTransformationScript.esd1TagNum1ContentN = $("#con div:eq(0) a:eq(" + _EsdDynamicTransformationScript.num1 + ")");
    _EsdDynamicTransformationScript.esd1TagNum2ContentN = $("#con div:eq(1) a:eq(" + _EsdDynamicTransformationScript.num2 + ")");

    //第一块
    _EsdDynamicTransformationScript.esd1TagNum1.focus(function (e) {

        e = $(this).mouseover();
        $(document).bind("keydown.keydown_1", function (e) {
            if (e.shiftKey && e.keyCode == 9) {}
            else if (e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd1TagNum1Content1.focus();
                console.log(document.activeElement);
                return false;
            }
        });

    });
    _EsdDynamicTransformationScript.esd1TagNum1.blur(function () {

        $(document).unbind("keydown.keydown_1");
    });

    _EsdDynamicTransformationScript.esd1TagNum1Content1.focus(function () {
        $(document).bind("keydown.keydown_s1", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd1TagNum1.focus();
                return false;
            }
        });
    });
    _EsdDynamicTransformationScript.esd1TagNum1Content1.blur(function () {
        $(document).unbind("keydown.keydown_s1");
    });

    _EsdDynamicTransformationScript.esd1TagNum1ContentN.focus(function () {
        $(document).bind("keydown.keydown_e1", function (e) {
            if (e.shiftKey && e.keyCode == 9) {}
            else if (e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd1TagNum2.focus();
                return false;
            }
        });
    });
    _EsdDynamicTransformationScript.esd1TagNum1ContentN.blur(function () {
        $(document).unbind("keydown.keydown_e1");
    });

    //第二块
    _EsdDynamicTransformationScript.esd1TagNum2.focus(function (e) {
        e = $(this).mouseover();
        $(document).bind("keydown.keydown_2", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd1TagNum1.mouseover();
                _EsdDynamicTransformationScript.esd1TagNum1ContentN.focus();
                return false;
            } else if (e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd1TagNum2Content1.focus();
                console.log(document.activeElement);
                return false;
            }
        });

    });
    _EsdDynamicTransformationScript.esd1TagNum2.blur(function () {
        $(document).unbind("keydown.keydown_2");
    });

    //第二部分
    //各个选项名称对应的内容数量
    _EsdDynamicTransformationScript.num3 = $("#con2 div:eq(0) a").length - 1;
    _EsdDynamicTransformationScript.num4 = $("#con2 div:eq(1) a").length - 1;

    //各个选项名称
    _EsdDynamicTransformationScript.esd2TagNum1 = $("#tit2 li:eq(0) a");
    _EsdDynamicTransformationScript.esd2TagNum2 = $("#tit2 li:eq(1) a");

    //各个选项中的第一个内容
    _EsdDynamicTransformationScript.esd2TagNum1Content1 = $("#con2 div:eq(0) a:eq(0)");
    _EsdDynamicTransformationScript.esd2TagNum2Content1 = $("#con2 div:eq(1) a:eq(0)");

    //各个选项中的最后一个内容
    _EsdDynamicTransformationScript.esd2TagNum1ContentN = $("#con2 div:eq(0) a:eq(" + _EsdDynamicTransformationScript.num3 + ")");
    _EsdDynamicTransformationScript.esd2TagNum2ContentN = $("#con2 div:eq(1) a:eq(" + _EsdDynamicTransformationScript.num4 + ")");

    //第一块
    _EsdDynamicTransformationScript.esd2TagNum1.focus(function (e) {

        e = $(this).mouseover();
        $(document).bind("keydown.keydown_1", function (e) {
            if (e.shiftKey && e.keyCode == 9) {}
            else if (e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd2TagNum1Content1.focus();
                console.log(document.activeElement);
                return false;
            }
        });

    });
    _EsdDynamicTransformationScript.esd2TagNum1.blur(function () {

        $(document).unbind("keydown.keydown_1");
    });

    _EsdDynamicTransformationScript.esd2TagNum1Content1.focus(function () {
        $(document).bind("keydown.keydown_s1", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd2TagNum1.focus();
                return false;
            }
        });
    });
    _EsdDynamicTransformationScript.esd2TagNum1Content1.blur(function () {
        $(document).unbind("keydown.keydown_s1");
    });

    _EsdDynamicTransformationScript.esd2TagNum1ContentN.focus(function () {
        $(document).bind("keydown.keydown_e1", function (e) {
            if (e.shiftKey && e.keyCode == 9) {}
            else if (e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd2TagNum2.focus();
                return false;
            }
        });
    });
    _EsdDynamicTransformationScript.esd2TagNum1ContentN.blur(function () {
        $(document).unbind("keydown.keydown_e1");
    });

    //第二块
    _EsdDynamicTransformationScript.esd2TagNum2.focus(function (e) {
        e = $(this).mouseover();
        $(document).bind("keydown.keydown_2", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd2TagNum1.mouseover();
                _EsdDynamicTransformationScript.esd2TagNum1ContentN.focus();
                return false;
            } else if (e.keyCode == 9) {
                _EsdDynamicTransformationScript.esd2TagNum2Content1.focus();
                console.log(document.activeElement);
                return false;
            }
        });

    });
    _EsdDynamicTransformationScript.esd2TagNum2.blur(function () {
        $(document).unbind("keydown.keydown_2");
    });

    // ---------------------------- 国务院iframe 开始 -----------------------------

    //将iframe所包含的a链接数 第一个a元素 最后一个a元素赋值给第一个参数的js对象
    _EsdDynamicTransformationScript.getIframeInfos = function (jsObj, iframeObj) {
        if (iframeObj != undefined) {
            jsObj.aLink_num = iframeObj.contentWindow.document.getElementsByTagName("a").length;
            jsObj.first_aLink = iframeObj.contentWindow.document.getElementsByTagName("a")[0];
            jsObj.last_aLink = iframeObj.contentWindow.document.getElementsByTagName("a")[jsObj.aLink_num - 1];
            jsObj.self = iframeObj;
        }
    };

    //声明iframe操作对象
    _EsdDynamicTransformationScript.iframe1 = {};
    _EsdDynamicTransformationScript.iframe2 = {};

    _EsdDynamicTransformationScript.iframeElement1 = document.getElementsByTagName("iframe")[0]; // 需要修改 这里的iframe获取
    _EsdDynamicTransformationScript.iframeElement2 = document.getElementsByTagName("iframe")[1]; // 需要修改 这里的iframe获取

    //选项卡标签 jquery对象
    _EsdDynamicTransformationScript.iframeTab1 = $("#tit1 li:eq(0) a"); // 需要修改 这里的tab获取
    _EsdDynamicTransformationScript.iframeTab2 = $("#tit1 li:eq(1) a"); // 需要修改 这里的tab获取

    // 判断iframe是否有效
    if ((_EsdDynamicTransformationScript.iframeElement1 != undefined) && (_EsdDynamicTransformationScript.iframeElement2 != undefined)) {

        // 当iframe都加载完毕后执行代码 使用setInterval
        _EsdDynamicTransformationScript.iframeInterval = setInterval(function () {

                if ((_EsdDynamicTransformationScript.iframeElement1.contentWindow.document.getElementsByTagName("a")[0] != undefined)
                     && _EsdDynamicTransformationScript.iframeElement2.contentWindow.document.getElementsByTagName("a")[0] != undefined) {
                    clearInterval(_EsdDynamicTransformationScript.iframeInterval);

                    //通过方法赋值
                    _EsdDynamicTransformationScript.getIframeInfos(_EsdDynamicTransformationScript.iframe1, _EsdDynamicTransformationScript.iframeElement1);
                    _EsdDynamicTransformationScript.getIframeInfos(_EsdDynamicTransformationScript.iframe2, _EsdDynamicTransformationScript.iframeElement2);

                    //第一个标签 切换
                    _EsdDynamicTransformationScript.iframeTab1.focus(function (e) {
                        console.log("tab1获取到焦点");
                        e = $(this).mouseover();
                        $(document).bind("keydown.iframeKeydown_1", function (e) {
                            if (e.shiftKey && e.keyCode == 9) {
                                console.log("tab1向回切换");
                                //_EsdDynamicTransformationScript.iframeTab1.trigger("blur");
                                $(".zly_tbbg3.zly_20180914bt:eq(1) H2 A").focus();
                                return false;
                            } else if (e.keyCode == 9) {
                                console.log("tab1继续切换到iframe上");
                                _EsdDynamicTransformationScript.iframeTab1.trigger("blur");
                                $(_EsdDynamicTransformationScript.iframe1.self).focus();
                                console.log(document.activeElement);
                                return false;
                            }
                        });
                    });
                    _EsdDynamicTransformationScript.iframeTab1.blur(function () {
                        $(document).unbind("keydown.iframeKeydown_1");
                    });

                    //第一个标签的第一个链接
                    $(_EsdDynamicTransformationScript.iframe1.first_aLink).focus(function () {
                        console.log("第一个iframe的第一条获得焦点");
                        $(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).bind("keydown.iframeKeydown_first1", function (e) {
                            if (e.shiftKey && e.keyCode == 9) {
                                console.log("第一个iframe的第一条向上切换");
                                $(document).trigger("blur");
                                _EsdDynamicTransformationScript.iframeTab1.focus();
                                return false;
                            } else if (e.keyCode == 9) {
                                console.log("第一个iframe的第一条继续切换");
                            }
                        });
                    });
                    $(_EsdDynamicTransformationScript.iframe1.first_aLink).blur(function () {
                        $(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).unbind("keydown.iframeKeydown_first1");
                    });

                    //第一个标签的最后一个链接
                    $(_EsdDynamicTransformationScript.iframe1.last_aLink).focus(function () {
                        console.log("第一个iframe的最后一条获得焦点");
                        $(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).bind("keydown.iframeKeydown_first1", function (e) {
                            if (e.shiftKey && e.keyCode == 9) {
                                console.log("第一个iframe的最后一条向上切换");
                            } else if (e.keyCode == 9) {
                                console.log("第一个iframe的最后一条继续切换 到下一个标签");
                                $(document).trigger("blur");
                                _EsdDynamicTransformationScript.iframeTab2.focus();
                                return false;
                            }
                        });
                    });
                    $(_EsdDynamicTransformationScript.iframe1.last_aLink).blur(function () {
                        $(_EsdDynamicTransformationScript.iframe1.self.contentWindow.document).unbind("keydown.iframeKeydown_first1");
                    });

                    //第二个标签切换
                    _EsdDynamicTransformationScript.iframeTab2.focus(function (e) {
                        console.log("tab2获取到焦点");
                        e = $(this).mouseover();
                        $(document).bind("keydown.iframeKeydown_2", function (e) {
                            if (e.shiftKey && e.keyCode == 9) {
                                console.log("第二个标签向回切换 到第一个标签的最后一条");
                                _EsdDynamicTransformationScript.iframeTab2.trigger("blur");
                                _EsdDynamicTransformationScript.iframeTab1.mouseover();
                                $(_EsdDynamicTransformationScript.iframe1.last_aLink).focus();
                                return false;
                            } else if (e.keyCode == 9) {
                                _EsdDynamicTransformationScript.iframeTab2.trigger("blur");
                                $(_EsdDynamicTransformationScript.iframe2.self).focus();
                                console.log(document.activeElement);
                                return false;
                            }
                        });

                    });
                    _EsdDynamicTransformationScript.iframeTab2.blur(function () {
                        $(document).unbind("keydown.iframeKeydown_2");
                    });
                }

            }, 500);

    }
    // ---------------------------- 国务院iframe 结束 -----------------------------

    //-------------------------------动漫统计轮播 开始--------------------------------------
    $(".zly_dm a:first").focus(function (e) {  //动漫统计 连接
        $(this).bind("keydown", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
            	
            } else if (e.keyCode == 9) {
            	$(".zly_dm .nums a:eq(0)").mouseover();
            	$(".zly_dm .nums a:eq(0)").focus();
            	return false;
            }
        });

    });
    $(".zly_dm a:first").blur(function () {
        $(this).unbind("keydown");
    });
    
    $(".zly_dm .nums a:eq(0)").focus(function (e) {  //动漫统计 第一个轮播按钮 连接
        $(this).bind("keydown", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
            	$(".zly_dm a:first").focus();
            	return false;
            } else if (e.keyCode == 9) {
            	$(".zly_dm .nums a:eq(1)").mouseover();
            	$(".zly_dm .nums a:eq(1)").focus();
            	return false;
            }
        });

    });
    $(".zly_dm .nums a:eq(0)").blur(function () {
        $(this).unbind("keydown");
    });
    
    $(".zly_dm .nums a:eq(1)").focus(function (e) {  //动漫统计 第二个轮播按钮 连接
        $(this).bind("keydown", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
            	$(".zly_dm .nums a:eq(0)").mouseover();
            	$(".zly_dm .nums a:eq(0)").focus();
            	return false;
            } else if (e.keyCode == 9) {
            	$(".zly_dm .nums a:eq(2)").mouseover();
            	$(".zly_dm .nums a:eq(2)").focus();
            	return false;
            }
        });

    });
    $(".zly_dm .nums a:eq(1)").blur(function () {
        $(this).unbind("keydown");
    });
    
    $(".zly_dm .nums a:eq(2)").focus(function (e) {  //动漫统计 第三个轮播按钮 连接
        $(this).bind("keydown", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
            	$(".zly_dm .nums a:eq(1)").mouseover();
            	$(".zly_dm .nums a:eq(1)").focus();
            	return false;
            } else if (e.keyCode == 9) {
            	$(".zly_qzul a:first").focus();
            	return false;
            }
        });

    });
    $(".zly_dm .nums a:eq(2)").blur(function () {
        $(this).unbind("keydown");
    });
    
    $(".zly_qzul a:first").focus(function (e) {  //动漫统计 下方债权清单
        $(this).bind("keydown", function (e) {
            if (e.shiftKey && e.keyCode == 9) {
            	$(".zly_dm .nums a:eq(2)").mouseover();
            	$(".zly_dm .nums a:eq(2)").focus();
            	return false;
            } else if (e.keyCode == 9) {
            	
            }
        });

    });
    $(".zly_qzul a:first").blur(function () {
        $(this).unbind("keydown");
    });
    //-------------------------------动漫统计轮播 结束--------------------------------------
}
